package com.javabasic.algorithm.leetcode;

/**
 * @Author xiongmin
 * @Description //TODO
 * @Date 2020/3/1 19:27
 * @Version 1.0
 **/
public class ValidPalindrome {

    public boolean isPalindrome(String s) {
        s = s.toLowerCase();
        int len = s.length();
        int left = 0, right = len - 1;
        char chLeft = ',', chRight = ',';
        boolean flag = true;
        while (left < right) {
            chLeft = s.charAt(left);
            chRight = s.charAt(right);
            while (left < len && (!(chLeft >= '0' && chLeft <= '9' || chLeft >= 'a' && chLeft <= 'z'))) {
                left++;
                if (left == len) break;
                chLeft = s.charAt(left);
            }
            while (right >= 0 && (!(chRight >= '0' && chRight <= '9' || chRight >= 'a' && chRight <= 'z'))) {

                right--;
                if (right == 0) break;
                chRight = s.charAt(right);

            }
            System.out.printf("%c %c\n",chLeft,chRight);
            if (chLeft != chRight) {
                if (left == len && right == -1 && flag) {
                    return true;
                }
                return false;
            } else {
                left++;
                right--;
                flag = false;
            }
        }
        return true;
    }
}
